//Home模块的小仓库
import { reqgetCategoryList, getBannerList, getFloorList } from '@/api'

const state = {
  //存储三级菜单的数据
  catagoryList: [],
  //轮播图的数据
  bannerList: [],
  //floor的数据
  floorList: [],
}
//mutations是唯一修改state的地方
const mutations = {
  CATEGORYLIST(state, value) {
    state.catagoryList = value
  },
  GETBANNERLIST(state, value) {
    state.bannerList = value
  },
  GETFLOORLIST(state, value) {
    state.floorList = value
  },
}
//action：处理用户派发事件，可以书写异步语句，自己的逻辑
const actions = {
  async catagoryList(context) {
    const result = await reqgetCategoryList()
    if (result && result.code == 200) {
      context.commit('CATEGORYLIST', result.data)
    }
  },
  //获取首页轮播图的数据
  async getBannerList(context) {
    const result = await getBannerList()
    if (result && result.code == 200) {
      context.commit('GETBANNERLIST', result.data)
    }
  },
  //获取floor的数据
  async getFloorList(context) {
    const result = await getFloorList()
    if (result.code == 200) {
      context.commit('GETFLOORLIST', result.data)
    }
  },
}

const getters = {}

export default {
  namespaced: 'home',
  state,
  mutations,
  actions,
  getters,
}
